<template>
  <div>
    <el-card>
      <el-table :data="classList" size="small" stripe border>
        <el-table-column prop="className" label="班级名称"  width="150" align="center">
          <template slot-scope="scope">
            {{ scope.row.className ? scope.row.className :'暂无' }}
          </template>
        </el-table-column>
        <el-table-column prop="classWeekday" label="上课时间"  align="center">
          <template slot-scope="scope">
            {{ scope.row.classWeekday&&scope.row.classStartNum&&scope.row.classEndNum?'周'+scope.row.classWeekday+' '+'（第'+scope.row.classStartNum+'节至第'+scope.row.classEndNum+'节）':'暂无数据' }}
          </template>
        </el-table-column>
        <el-table-column prop="classState" label="报名状态"  align="center">
          <template slot-scope="scope">
            <el-tag
              :type="scope.row.classState ===0 ? 'info' : scope.row.classState=== 1 ? '':scope.row.classState === 2 ?'danger':''"
            >
              {{ scope.row.classState===0 ? '未开启报名' :scope.row.classState===1 ?'报名进行':scope.row.classState===2 ?'报名截止':'暂无' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="limitOfNumber" label="已报名/限制数"   align="center">
          <template slot-scope="scope">
            {{ scope.row.limitOfNumber ? scope.row.currentNumber?scope.row.currentNumber+'/'+scope.row.limitOfNumber:'0/'+scope.row.limitOfNumber :'暂无数据' }}
          </template>
        </el-table-column>
        <el-table-column prop="openingWeek" label="开班星期"   align="center"/>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { getOrdersList } from '../../../api/order'
import { getClass } from '../../../api/class'

export default {
  name: 'course',
  data() {
    return {
      orderList: [],
      classList: []
    }
  },
  created() {
    this.getOrders()
  },
  methods: {
    getOrders() {
      getOrdersList()
        .then(res => {
          for ( var i = 0, j = 0; j < res.data.list.length; j++) {
            if (res.data.list[i].state === 1 && res.data.list[i].type === 'signUp') {
              this.orderList[i] = res.data.list[j]
              console.log('res', res.data.list[j])
              i++
            }
          }
          this.getClassList()
          console.log('res', res.data.list)
          console.log('orderlist', this.orderList)
        })
        .catch(err => {
          this.$message.error('获取订单列表失败！')
        })
    },
    getClassList() {
      for ( var i = 0; i < this.orderList.length; i++){
        getClass({
          cid: this.orderList[i].cid
        }).then(res => {
          this.classList = res.data.list
        })
      }
    }
  }
}
</script>

<style scoped>

</style>
